﻿using System;
using System.Configuration;
using System.Windows.Forms;
using JiraGenCommon;
using JiraGenerator.Properties;

namespace JiraGenerator
{
    public partial class PreferencesForm : JiraBaseForm
    {
        public PreferencesForm()
        {
            InitializeComponent();
        }

        private void PreferencesForm_Load(object sender, EventArgs e)
        {
            var jiraSoapUrl = ConfigurationSettings.AppSettings["JiraSoapServiceUrl"];
            txtJiraSoapSvcUrl.Text = jiraSoapUrl;

            var jiraDefaultUser = ConfigurationSettings.AppSettings["default_jira_user"];
            txtJiraDefaultUser.Text = jiraDefaultUser;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void btnNext_Click(object sender, EventArgs e)
        {
            try
            {
                GlobalVariables.Current.JiraSoapServiceUrl = txtJiraSoapSvcUrl.Text.Trim();
                GlobalVariables.Current.JiraDefaultUser = txtJiraDefaultUser.Text.Trim();

                if(UIUtils.ShowMessageBox(Resources.PreferencesForm_btnNext_Click_Save_successfully__Do_you_want_to_continue_, 
                    MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.No)
                {
                    this.Dispose();
                }
            }
            catch (Exception exception)
            {
                UIUtils.ShowMessageBox(
                    string.Format(Resources.Occurs_error_when_Saving__Error_message__0_, exception.Message),
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            
        }
    }
}
